package spring.yongongsystem.controller.admin;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import spring.yongongsystem.POJO.dto.AdminDTO;
import spring.yongongsystem.POJO.dto.MerchantDTO;
import spring.yongongsystem.POJO.dto.MerchantPageQueryDTO;
import spring.yongongsystem.result.PageResult;
import spring.yongongsystem.result.Result;
import spring.yongongsystem.service.MerchantService;
@CrossOrigin(origins = "http://localhost:5173")
@RestController("adminMerchantsController")
@RequestMapping("/admin/merchant")
@Api(tags = "管理员商家相关接口")
@Slf4j
public class MerchantsController {

    @Autowired
    private MerchantService merchantService;
    /**
     * 新增商家
     * @param merchantDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增商家")
    public Result save(@RequestBody MerchantDTO merchantDTO){
        log.info("新增商家：{}",merchantDTO);
        merchantService.save(merchantDTO);
        return Result.success();
    }

    /**
     * 商家分页查询
     * @param merchantPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("员工分页查询")
    public Result<PageResult> page(MerchantPageQueryDTO merchantPageQueryDTO){
        log.info("员工分页查询，参数为：{}", merchantPageQueryDTO);
        PageResult pageResult = merchantService.pageQuery(merchantPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 删除商家
     * @param id
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除商家")
    public Result<String> deleteById(Long id){
        log.info("删除商家：{}", id);
        merchantService.deleteById(id);
        return Result.success();
    }

    /**
     * 编辑商家信息
     * @param merchantDTO
     * @return
     */
    @PutMapping
    @ApiOperation("编辑商家信息")
    public Result update(@RequestBody MerchantDTO merchantDTO){
        log.info("编辑商家信息：{}", merchantDTO);
        merchantService.update(merchantDTO);
        return Result.success();
    }
}
